package io.gitee.zicai.service.provider.service

import io.gitee.zicai.service.common.IHelloService
import org.apache.dubbo.config.annotation.Service
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.web.ServerProperties
import org.springframework.cloud.context.config.annotation.RefreshScope
import org.springframework.stereotype.Component

/**
 * HelloService
 * @author zicai
 * @since 2019-12-05
 */
@Service
@Component
@RefreshScope
open class HelloService : IHelloService {

    private val log = LoggerFactory.getLogger(this::class.java)

    @Autowired
    private lateinit var serverProperties: ServerProperties

    @Value("\${zicai.title:'localValue000'}")
    private lateinit var zicaiTitle: String

    override fun hello(msg: String) = "Hello from ${this.javaClass.simpleName}:${serverProperties.port}, msg -> $msg"
            .also { log.info("provider HelloService hello -> $it") }

    override fun config() = "value from ${this.javaClass.simpleName}:${serverProperties.port}, title -> $zicaiTitle"
            .also { log.info("provider HelloService config -> $it") }
}